package acm.pta5;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class T1_8 {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String [] read = in.readLine().split(" ");
        int ra = Integer.parseInt(read[0]);
        int ca = Integer.parseInt(read[1]);
        int A[][] = new int[ra][ca];
        for (int i = 0; i < ra; i++) {
            String datas[] = in.readLine().split(" ");
            for (int j = 0; j < ca; j++) {
                A[i][j] = Integer.parseInt(datas[j]);
            }
        }

        String [] len2 = in.readLine().split(" ");
        int rb = Integer.parseInt(len2[0]);
        int cb = Integer.parseInt(len2[1]);
        int B[][] = new int[rb][cb];
        for (int i = 0; i < rb; i++) {
            String datas[] = in.readLine().split(" ");
            for (int j = 0; j < cb; j++) {
                B[i][j] = Integer.parseInt(datas[j]);
            }
        }

        if (ca == rb) {
            int C[][] = new int[105][105];
            for (int i = 0; i < ra; i++) {
                for (int j = 0; j < cb; j++) {
                    for (int k = 0; k < rb; k++) {
                        C[i][j] += A[i][k] * B[k][j];
                    }
                }
            }
            System.out.println(ra + " " + cb);
            for (int i = 0; i < ra; i++) {
                for (int j = 0; j < cb; j++) {
                    if (j == cb - 1) {
                        System.out.println(C[i][j]);
                    } else {
                        System.out.print(C[i][j] + " ");
                    }
                }
            }
        } else {
            System.out.println("Error: " + ca + " != " + rb);
        }
        in.close();
    }
}
